<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\CentersController;
use App\Http\Controllers\InstructorsController;
use App\Http\Controllers\MembersController;
use App\Http\Controllers\ReportsController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/', function (){

    if (Auth::check()){
        return redirect(route('centers'));
    }

    return view('auth.login');
})->name('login');


Route::post('/login', [AuthController::class,'login'])->name('login.auth');



Route::group(['middleware' => ['auth']], function() {

    Route::get('/centers', [CentersController::class, 'show'])->name('centers');
    Route::get('/centers/{center}/edit', [CentersController::class, 'edit'])->name('centers.edit');
    Route::patch('/centers/{center}', [CentersController::class, 'update'])->name('centers.update');

    Route::get('/reports', [ReportsController::class, 'show'])->name('reports');
    Route::post('/reports', [ReportsController::class, 'form'])->name('reports__filter');
    Route::get('/reports/add', [ReportsController::class, 'add'])->name('reports.add');
    Route::post('/reports/store', [ReportsController::class, 'store'])->name('reports.store');
    Route::delete('/reports/{report}/delete', [ReportsController::class, 'delete'])->name('reports.delete');
    Route::get('/reports/{report}/edit', [ReportsController::class, 'edit'])->name('reports.edit');
    Route::patch('/reports/{report}', [ReportsController::class, 'update'])->name('reports.update');
    Route::post('/reports/excel',[ReportsController::class, 'excel'])->name('reports.excel');



    Route::get('/members', [MembersController::class, 'show'])->name('members');
    Route::get('/members/{member}/edit', [MembersController::class, 'edit'])->name('members.edit');
    Route::patch('/members/{member}', [MembersController::class, 'update'])->name('members.update');
    Route::get('/members/add', [MembersController::class, 'add'])->name('members.add');
    Route::post('/members/store', [MembersController::class, 'store'])->name('members.store');
    Route::delete('/members/{member}/delete', [MembersController::class, 'delete'])->name('members.delete');
    Route::post('/members', [MembersController::class, 'form'])->name('members__filter');
    Route::post('/members/excel',[MembersController::class, 'excel'])->name('members.excel');


    Route::get('/instructors', [InstructorsController::class, 'show'])->name('instructors');
//    Route::get('/instructors/export', [InstructorsController::class, 'show'])->name('instructors');
    Route::get('/instructors/{instructor}/edit', [InstructorsController::class, 'edit'])->name('instructors.edit');
    Route::patch('/instructors/{instructor}', [InstructorsController::class, 'update'])->name('instructors.update');
    Route::get('/instructors/add', [InstructorsController::class, 'add'])->name('instructors.add');
    Route::get('/instructors/inactiveadd', [InstructorsController::class, 'inactiveadd'])->name('instructors.inactiveadd');
    Route::post('/instructors/store', [InstructorsController::class, 'store'])->name('instructors.store');
    Route::post('/instructors/storeinactive', [InstructorsController::class, 'storeinactive'])->name('instructors.storeinactive');
    Route::delete('/instructors/{instructor}/delete', [InstructorsController::class, 'delete'])->name('instructors.delete');
//    Route::get('/instructors', [InstructorsController::class, 'form'])->name('instructors__filter');



    Route::get('/logout', [AuthController::class,'logout'])->name('logout');
});
